package com.ts.utils;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ObjectToMapUtil {

	public static Map<String,Object> objectToMap(Object obj) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		Field[] fields = obj.getClass().getDeclaredFields();
		
		for (Field field : fields) {
			String varName = field.getName();
			boolean accessFlag = field.isAccessible();
			field.setAccessible(true);
			Object o = field.get(obj);
			if(o != null){
				map.put(varName, o.toString());
			}
			
			field.setAccessible(accessFlag);
		}
		map.remove("serialVersionUID");
		return map;
	}
	
	
	public static void main(String[] args) throws Exception {

	}
}
